home *** CD-ROM | disk | FTP | other *** search
- unit Dateform;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, Grids, Calendar, StdCtrls, Buttons;
-
- type
- TDateSelector = class(TForm)
- Calendar1: TCalendar;
- OKButton: TBitBtn;
- CancelButton: TBitBtn;
- HelpButton: TBitBtn;
- Label1: TLabel;
- procedure FormCreate(Sender: TObject);
- procedure OKButtonClick(Sender: TObject);
- procedure HelpButtonClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- procedure DateSelSetCaption (Caption: PChar); export;
- procedure DateSelSetHelpInfo (HelpFile: PChar; HelpContext: LongInt); export;
- function DateSelDialog (var TheDate: Integer): Bool; export;
-
- var
- DateSelector: TDateSelector;
-
- implementation
-
- {$R *.DFM}
-
- const
- CustomCaption: String = ''; { If empty, use designed-in value }
- HelpFileName: PChar = Nil; { If Nil, disable help button }
- dwHelpContext: LongInt = -1; { Help context to call }
- iDate: Integer = 0; { An invalid value until initted }
-
- {--------------------------------------------------------------}
- { Name: FormCreate }
- { Purpose: OnCreate handler for the form. It sets a custom }
- { caption if one has been supplied and disables the }
- { Help buttom if we haven't got any help info. }
- {--------------------------------------------------------------}
- procedure TDateSelector.FormCreate(Sender: TObject);
- begin
- { Set custom caption if one has been supplied }
- if CustomCaption <> '' then Caption := CustomCaption;
-
- { See if Help stuff set up. If not, disable Help button }
- if (HelpFileName = Nil) or (dwHelpContext = -1) then
- HelpButton.Enabled := False;
- end;
-
- {--------------------------------------------------------------}
- { Name: OKButtonClick }
- { Purpose: Shared event handler for OK/Cancel/Double-clicks }
- {--------------------------------------------------------------}
- procedure TDateSelector.OKButtonClick(Sender: TObject);
- begin
- { If this wasn't a Cancel, set the iDate global }
- if Sender <> CancelButton then iDate := Calendar1.Day;
- Close;
- end;
-
- {--------------------------------------------------------------}
- { Name: HelpButtonClick }
- { Purpose: Invoke the Windows Help engine if Help clicked. }
- {--------------------------------------------------------------}
- procedure TDateSelector.HelpButtonClick(Sender: TObject);
- begin
- { Just call the Help Engine with the info we've been given }
- WinHelp (Handle, HelpFileName, Help_Context, dwHelpContext);
- end;
-
- {--------------------------------------------------------------}
- { Name: DateSelSetCaption }
- { Purpose: DLL Interface routine. Sets up a custom caption. }
- {--------------------------------------------------------------}
- procedure DateSelSetCaption (Caption: PChar);
- begin
- { StrPas doesn't check for Nil strings, so watch it ! }
- if Caption <> Nil then CustomCaption := StrPas (Caption);
- end;
-
- {--------------------------------------------------------------}
- { Name: DateSelSetHelpInfo }
- { Purpose: DLL Interface routine. Sets up help information. }
- {--------------------------------------------------------------}
- procedure DateSelSetHelpInfo (HelpFile: PChar; HelpContext: LongInt);
- begin
- { If we've previously been called, clear old string }
- if HelpFileName <> Nil then StrDispose (HelpFileName);
-
- { Now set up the new stuff }
- HelpFileName := StrNew (HelpFile);
- dwHelpContext := HelpContext;
- end;
-
- {--------------------------------------------------------------}
- { Name: DateSelDialog }
- { Purpose: DLL Interface routine. Execute the actual dialog. }
- {--------------------------------------------------------------}
- function DateSelDialog (var TheDate: Integer): Bool;
- begin
- { no date selected yet }
- iDate := 0;
- { Create the form instance }
- DateSelector := TDateSelector.Create (Application);
- try
- { Display the dialog }
- DateSelector.ShowModal;
- finally
- { Destroy the form instance }
- DateSelector.Free;
- Result := iDate <> 0;
- if Result then TheDate := iDate;
- end;
- end;
-
- end.
-